package net.sx.minemodule.mvp.presenters;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.R;
import net.sx.minemodule.mvp.model.HistoryIntegralModel;
import net.sx.minemodule.mvp.model.IntegralInfoModel;

import java.util.List;

/**
 * add shibo.zheng
 * 19/06/14
 * 历史积分记录presenter
 */

public class MineIntegralRecordPresenter extends AbstractRefreshPresenter<RefreshingView> {
    private static final String TAG = "IntegralRecordPreTag";
    private String integralType;

    public MineIntegralRecordPresenter(RefreshingView mView) {
        super(mView);
        emptyItem.setResId(R.mipmap.mine_no_message);
        emptyItem.setContent("暂无消息");
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        if ("expiredIntegral".equals(integralType)) {           //30天内过期积分
            //TODO
        } else if ("integralRecording".equals(integralType)) {  //历史积分记录
            MineApiUtils.getHistoryIntegral(1, 10, subModelList -> {
                List<HistoryIntegralModel> models = JSON.parseArray(subModelList.getItems(), HistoryIntegralModel.class);
                parserData(isLoadMore, models);
            }, throwable -> Log.d(TAG, "accept: throwable == " + throwable.toString()));
        } else if ("integralInfo".equals(integralType)) {       //积分明细
            MineApiUtils.getIntegralInfo(1, 10, subModelList -> {
                List<IntegralInfoModel> integralInfoModels = JSON.parseArray(subModelList.getItems(), IntegralInfoModel.class);
                parserData(isLoadMore, integralInfoModels);
            }, throwable -> Log.d(TAG, "accept: throwable == " + throwable.toString()));
        }
    }

    public void setRecordDataType(String integralType) {
        this.integralType = integralType;
    }
}
